#this is required to have CLEAR in make file which is a console-dependant function
#shouldn't be used though...
#export TERM=xterm

#variable definitions
COMPILER       := cc
#SOURCES_TST    := TheTest.c
#OBJECTS_TST    := $(SOURCES_TST:.c=.o)
#OUTPUT         := TheTest.bin
KERNEL_DIR     := /lib/modules/$(shell uname -r)/build
PWD            := $(shell pwd)
SOURCES_DRIVER := ExamTest.c DriverCore.c
OBJECTS_DRIVER := $(SOURCES_DRIVER:.c=.o)


#make directive for Kernel driver object
obj-m        := $(OBJECTS_DRIVER)

#Build directives
ExamTest:
	@echo "Building the ELE784 Test Exam driver (by Vince !!!)..."
	@echo "Exam Test"
	@echo "Now building..."
	@make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
	@echo "Build finished... ExamTest ready to be installed"
	@echo "\nSVP, écrire 'sudo insmod ./ExamTest.ko' pour installer le pilote"
	@echo "(Retirer du système avec 'sudo rmmod ExamTest')\n"

#TheTest:
#	@echo "Now building The Test "
#	@echo "Compiling..."
#	@$(COMPILER) -c $(SOURCES_TST)
#	@echo "Linking..."
#	@$(COMPILER) -o $(OUTPUT) $(OBJECTS_TST)
#	@echo "Build finished... Generated file: $(OUTPUT)\n" 
#	@echo "SVP, écrire './$(OUTPUT)' pour démarrer le test !\n"

all: 	
#	@clear
	@echo "BUILDING ALL..."
	@make ExamTest
#	@make TheTest

#Clean up module
clean:
	@-rm -f *.bin *.o *.ko .*.cmd .*.flags *.mod.c Module.symvers modules.order
	@-rm -rf .tmp_versions
	@echo "Cleaned up all objects and outputs from workspace"

